// 地图服务工具类
const MapService = {
  // 打开高德地图导航
  openAmapNavigation(destination) {
    return new Promise((resolve, reject) => {
      // 检查是否安装了高德地图
      wx.getSystemInfo({
        success: (res) => {
          if (res.platform === 'android') {
            // Android平台
            wx.navigateToMiniProgram({
              appId: 'wx5f4d42c5a7b1a4d9', // 高德地图小程序AppID
              path: `pages/route/route?destination=${destination.latitude},${destination.longitude}&destName=${destination.name}`,
              success: () => {
                resolve();
              },
              fail: (error) => {
                console.error('打开高德地图失败：', error);
                reject(new Error('打开高德地图失败，请确保已安装高德地图'));
              }
            });
          } else if (res.platform === 'ios') {
            // iOS平台
            wx.navigateToMiniProgram({
              appId: 'wx5f4d42c5a7b1a4d9', // 高德地图小程序AppID
              path: `pages/route/route?destination=${destination.latitude},${destination.longitude}&destName=${destination.name}`,
              success: () => {
                resolve();
              },
              fail: (error) => {
                console.error('打开高德地图失败：', error);
                reject(new Error('打开高德地图失败，请确保已安装高德地图'));
              }
            });
          } else {
            reject(new Error('不支持当前平台'));
          }
        },
        fail: (error) => {
          reject(error);
        }
      });
    });
  }
};

export default MapService; 